﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SoftwareClass_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string username = textBox1.Text;
            string userpassword = textBox2.Text;
            bool lname = !string.IsNullOrEmpty(username);
            bool lpassword = !string.IsNullOrEmpty(userpassword);

            string sqlregister = string.Format("select * from Users where Username = '{0}' and [Password] = '{1}'", username,userpassword);
            string consql = "server =PC-202001311751\\MYSQLSERVER ;uid =yun0823 ;pwd =jxy130452 ;database =Blogs ";
            SqlConnection sqlconn = new SqlConnection(consql);
            SqlCommand sqlcomm = new SqlCommand(sqlregister, sqlconn);
            sqlconn.Open();
            int i = Convert.ToInt32(sqlcomm.ExecuteScalar());
            //登录验证
            if (!lname)
            {
                MessageBox.Show("用户名不能为空");
            }
            else if(!lpassword)
            {
                MessageBox.Show("密码不能为空");
            }else
            {
                if (i > 0)
            {
                MessageBox.Show("登陆成功！");
                Homepage homepage = new Homepage();
                homepage.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("用户名或密码错误");
            }
            }
           

           
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            Login login = new Login();
            login.Show();
        }
    }
}
